package org.jeecg.modules.rental.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.PermissionData;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.rental.entity.RentalCouponCategory;
import org.jeecg.modules.rental.entity.RentalCouponOrder;
import org.jeecg.modules.rental.service.IRentalCouponOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

 /**
 * @Description: 卡券订单表
 * @Author: jeecg-boot
 * @Date:   2024-08-20
 * @Version: V1.0
 */
@Api(tags="卡券订单表")
@RestController
@RequestMapping("/rental/coupon-order")
@Slf4j
public class RentalCouponOrderController extends JeecgController<RentalCouponOrder, IRentalCouponOrderService> {
	@Autowired
	private IRentalCouponOrderService rentalCouponOrderService;

//	@Autowired
//	private RentalPayAccountMapper rentalPayAccountMapper;
//
//	@Autowired
//	private RentalAccountCouponMapper rentalAccountCouponMapper;
//
	/**
	 * 分页列表查询
	 *
	 * @param rentalCouponOrder
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	//@AutoLog(value = "卡券订单表-分页列表查询")
	@ApiOperation(value = "卡券订单表-分页列表查询", notes = "卡券订单表-分页列表查询")
	@GetMapping(value = "/list")
	@PermissionData(pageComponent="rental/coupon/orderlist")
	public Result<IPage<RentalCouponOrder>> queryPageList(RentalCouponOrder rentalCouponOrder, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
														  @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
														  HttpServletRequest request) {
		QueryWrapper<RentalCouponOrder> queryWrapper = QueryGenerator.initQueryWrapper(rentalCouponOrder, request.getParameterMap());
		Page<RentalCouponOrder> page = new Page<RentalCouponOrder>(pageNo, pageSize);
		IPage<RentalCouponOrder> pageList = rentalCouponOrderService.selectJoinPage(page, queryWrapper);
		return Result.OK(pageList);
	}
	
	/**
	 *   添加
	 *
	 * @param rentalCouponOrder
	 * @return
	 */
	@AutoLog(value = "卡券订单表-添加")
	@ApiOperation(value="卡券订单表-添加", notes="卡券订单表-添加")
	@PostMapping(value = "/add")
	public Result<RentalCouponOrder> add(@RequestBody RentalCouponOrder rentalCouponOrder) {
		rentalCouponOrderService.save(rentalCouponOrder);
		return Result.OK("common.add.success");
	}
	
	/**
	 *  编辑
	 *
	 * @param rentalCouponOrder
	 * @return
	 */
	@AutoLog(value = "卡券订单表-编辑")
	@ApiOperation(value="卡券订单表-编辑", notes="卡券订单表-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody RentalCouponOrder rentalCouponOrder) {
		rentalCouponOrderService.updateById(rentalCouponOrder);
		return Result.OK("common.edit.success");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "卡券订单表-通过id删除")
	@ApiOperation(value="卡券订单表-通过id删除", notes="卡券订单表-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		rentalCouponOrderService.removeById(id);
		return Result.OK("common.delete.success");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "卡券订单表-批量删除")
	@ApiOperation(value="卡券订单表-批量删除", notes="卡券订单表-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.rentalCouponOrderService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("common.delete.batch.success");
	}


	 @ApiOperation(value="卡券订单客户端列表-分页列表查询", notes="卡券订单客户端列表-分页列表查询")
	 @GetMapping(value = "/order-list")
	 public Result<IPage<RentalCouponOrder>> orderListNew(RentalCouponOrder rentalCouponOrder, Page page) {
		 Page<RentalCouponOrder> pageList = rentalCouponOrderService.orderListNew(page, rentalCouponOrder);
		 return Result.OK(pageList);
	 }


//	 @ApiOperation(value="租车订单-分页列表查询", notes="租车订单-分页列表查询")
//	 @GetMapping(value = "/order-coupon-list")
//	 public Result<IPage<RentalCouponResp>> orderListCoupon(RentalCouponOrderReq rentalCouponOrderReq, Page page) {
//		 Page<RentalCouponResp> pageList = rentalCouponOrderService.orderListAcountCoupon(page, rentalCouponOrderReq);
//		 return Result.OK(pageList);
//	 }



	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "卡券订单表-通过id查询")
	@ApiOperation(value="卡券订单表-通过id查询", notes="卡券订单表-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<RentalCouponOrder> queryById(@RequestParam(name="id",required=true) String id) {
		RentalCouponOrder rentalCouponOrder = rentalCouponOrderService.getById(id);
		if(rentalCouponOrder==null) {
			return Result.error("common.query.not.found",null);
		}
		return Result.OK(rentalCouponOrder);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param rentalCouponOrder
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, RentalCouponOrder rentalCouponOrder) {
        return super.exportXls(request, rentalCouponOrder, RentalCouponOrder.class, "卡券订单表");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, RentalCouponOrder.class);
    }

	 /**
	  *   添加
	  *
	  * @param rentalCouponOrder
	  * @return
	  */
	 @AutoLog(value = "卡券订单表-添加")
	 @ApiOperation(value="卡券订单表-添加", notes="卡券订单表-添加")
	 @PostMapping(value = "/buy")
	 public Result<RentalCouponOrder> buy(@RequestBody RentalCouponOrder rentalCouponOrder) {
		 RentalCouponOrder couponOrder = rentalCouponOrderService.buy(rentalCouponOrder);
		 return Result.OK("创建卡券订单成功", couponOrder);
	 }

}
